module derelict.readline.readline;

private import derelict.util.loader;

extern(C) {
    typedef char* function(char*) pfreadline;
    typedef void function() pfrl_free_line_state;
    typedef void function() pfrl_cleanup_after_signal;
    typedef void function(char*, char*) pfrl_variable_bind;
    typedef void function() pfusing_history;
    typedef void function(char*) pfadd_history;
    pfreadline readline;
    pfrl_free_line_state rl_free_line_state;
    pfrl_cleanup_after_signal rl_cleanup_after_signal;
    pfrl_variable_bind rl_variable_bind;
    pfusing_history using_history;
    pfadd_history add_history;
}

private void load(SharedLib lib) {
    bindFunc(readline)("readline", lib);
    bindFunc(rl_free_line_state)("rl_free_line_state", lib);
    bindFunc(rl_cleanup_after_signal)("rl_cleanup_after_signal", lib);
    bindFunc(rl_variable_bind)("rl_variable_bind", lib);
    bindFunc(using_history)("using_history", lib);
    bindFunc(add_history)("add_history", lib);
}

GenericLoader DerelictReadline;
static this() {
    DerelictReadline.setup(
        "readline5.dll",
        "libreadline5.so",
        "",
        &load
    );
}
